# coding:utf-8
 
import json
from wsgiref.simple_server import make_server
import redis
 
 
# 定义函数，参数是函数的两个参数，都是python本身定义的，默认就行了。
def application(environ, start_response):
    # # 定义文件请求的类型和当前请求成功的code
    # start_response('200 OK', [('Content-Type', 'Content-Type:text/xml')])
    # # environ是当前请求的所有数据，包括Header和URL，body
    # environ['']
    start_response('200 OK', [('Content-Type', 'text/xml;cheset=utf-8')])
    paths=''.join(environ['PATH_INFO'])
    path=paths.split('/')
    if path[1] =='api':
        if  path[2] =='today':
            r = redis.Redis(host='47.104.9.64', port=6379,db=1)
            str=r.get('day_art')   #添加文章
            return str
        else:
            pass

    return '<h1>Hello, %s!</h1>'
 
 
if __name__ == "__main__":
    port = 80
    httpd = make_server("0.0.0.0", port, application)
    print "serving http on port {0}...".format(str(port))
    httpd.serve_forever()
